<html>
<head><meta charset="utf-8"><title>Getting rid of `#[macro_export] macro_rules` on 2021 edition · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20rid.20of.20.60.23.5Bmacro_export.5D.20macro_rules.60.20on.202021.20edition.html">Getting rid of `#[macro_export] macro_rules` on 2021 edition</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="213850126"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20rid%20of%20%60%23%5Bmacro_export%5D%20macro_rules%60%20on%202021%20edition/near/213850126" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20rid.20of.20.60.23.5Bmacro_export.5D.20macro_rules.60.20on.202021.20edition.html#213850126">(Oct 19 2020 at 21:42)</a>:</h4>
<p>It can be replaced with <code>pub macro_rules! { ... }</code>.</p>



<a name="213850213"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20rid%20of%20%60%23%5Bmacro_export%5D%20macro_rules%60%20on%202021%20edition/near/213850213" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20rid.20of.20.60.23.5Bmacro_export.5D.20macro_rules.60.20on.202021.20edition.html#213850213">(Oct 19 2020 at 21:43)</a>:</h4>
<p>The implementation part is trivial, and <code>#[macro_export]</code> is a weird and obviously legacy mechanism.</p>



<a name="213850264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20rid%20of%20%60%23%5Bmacro_export%5D%20macro_rules%60%20on%202021%20edition/near/213850264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20rid.20of.20.60.23.5Bmacro_export.5D.20macro_rules.60.20on.202021.20edition.html#213850264">(Oct 19 2020 at 21:43)</a>:</h4>
<p>It will address IDE concerns - <a href="https://github.com/rust-lang/rfcs/issues/1355#issuecomment-500139982">https://github.com/rust-lang/rfcs/issues/1355#issuecomment-500139982</a></p>



<a name="213850423"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20rid%20of%20%60%23%5Bmacro_export%5D%20macro_rules%60%20on%202021%20edition/near/213850423" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20rid.20of.20.60.23.5Bmacro_export.5D.20macro_rules.60.20on.202021.20edition.html#213850423">(Oct 19 2020 at 21:45)</a>:</h4>
<p>(Inspired by a PR reviewed today - <a href="https://github.com/rust-lang/rust/pull/77984#issuecomment-712445508">https://github.com/rust-lang/rust/pull/77984#issuecomment-712445508</a>)</p>



<a name="213851027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20rid%20of%20%60%23%5Bmacro_export%5D%20macro_rules%60%20on%202021%20edition/near/213851027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20rid.20of.20.60.23.5Bmacro_export.5D.20macro_rules.60.20on.202021.20edition.html#213851027">(Oct 19 2020 at 21:51)</a>:</h4>
<p>In more detail: any visibility annotation (<code>pub</code> or <code>pub(...)</code>)  "modularizes" the macro item, so it starts using regular item rules instead of the legacy <code>macro_rules</code> scoping.</p>



<a name="213851732"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20rid%20of%20%60%23%5Bmacro_export%5D%20macro_rules%60%20on%202021%20edition/near/213851732" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20rid.20of.20.60.23.5Bmacro_export.5D.20macro_rules.60.20on.202021.20edition.html#213851732">(Oct 19 2020 at 21:59)</a>:</h4>
<p>I wouldn't be opposed</p>



<a name="213851746"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20rid%20of%20%60%23%5Bmacro_export%5D%20macro_rules%60%20on%202021%20edition/near/213851746" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20rid.20of.20.60.23.5Bmacro_export.5D.20macro_rules.60.20on.202021.20edition.html#213851746">(Oct 19 2020 at 21:59)</a>:</h4>
<p>Does it require an edition, <span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span>?</p>



<a name="213851755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20rid%20of%20%60%23%5Bmacro_export%5D%20macro_rules%60%20on%202021%20edition/near/213851755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20rid.20of.20.60.23.5Bmacro_export.5D.20macro_rules.60.20on.202021.20edition.html#213851755">(Oct 19 2020 at 21:59)</a>:</h4>
<p>Or could we just do it on all editions</p>



<a name="213851782"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20rid%20of%20%60%23%5Bmacro_export%5D%20macro_rules%60%20on%202021%20edition/near/213851782" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20rid.20of.20.60.23.5Bmacro_export.5D.20macro_rules.60.20on.202021.20edition.html#213851782">(Oct 19 2020 at 21:59)</a>:</h4>
<p>I also think that using visibility modifiers for macros would be a nice change</p>



<a name="213851857"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20rid%20of%20%60%23%5Bmacro_export%5D%20macro_rules%60%20on%202021%20edition/near/213851857" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20rid.20of.20.60.23.5Bmacro_export.5D.20macro_rules.60.20on.202021.20edition.html#213851857">(Oct 19 2020 at 22:00)</a>:</h4>
<p>Oh, I guess we would want 2021 Edition in order to have <code>macro_rules! foo</code> be 'private', maybe?</p>



<a name="213851861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20rid%20of%20%60%23%5Bmacro_export%5D%20macro_rules%60%20on%202021%20edition/near/213851861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20rid.20of.20.60.23.5Bmacro_export.5D.20macro_rules.60.20on.202021.20edition.html#213851861">(Oct 19 2020 at 22:00)</a>:</h4>
<p>instead of "legacy scoping"</p>



<a name="213853629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20rid%20of%20%60%23%5Bmacro_export%5D%20macro_rules%60%20on%202021%20edition/near/213853629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20rid.20of.20.60.23.5Bmacro_export.5D.20macro_rules.60.20on.202021.20edition.html#213853629">(Oct 19 2020 at 22:20)</a>:</h4>
<p>An edition boundary or maybe using <code>pub(in self)</code> to opt into this new behavior would be required for private <code>macro_rules!</code></p>



<a name="213882437"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20rid%20of%20%60%23%5Bmacro_export%5D%20macro_rules%60%20on%202021%20edition/near/213882437" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20rid.20of.20.60.23.5Bmacro_export.5D.20macro_rules.60.20on.202021.20edition.html#213882437">(Oct 20 2020 at 07:21)</a>:</h4>
<p>Adding <code>pub</code> doesn't require an edition.<br>
Removing <code>#[macro_export]</code> does require an edition, of course, as a major breaking change.</p>
<p>I didn't actually think about modularizing "private" <code>macro_rules</code> without visibility, it's a breaking change requiring an edition, yes.<br>
Without this change a private modularized macro can be created with <code>pub(self) macro_rules</code>.<br>
Even now you can partially emulate it with</p>
<div class="codehilite"><pre><span></span><code>macro_rules! foo { ... }
use foo;
</code></pre></div>



<a name="213882736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20rid%20of%20%60%23%5Bmacro_export%5D%20macro_rules%60%20on%202021%20edition/near/213882736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20rid.20of.20.60.23.5Bmacro_export.5D.20macro_rules.60.20on.202021.20edition.html#213882736">(Oct 20 2020 at 07:25)</a>:</h4>
<p>If "private" <code>macro_rules</code> are modularized, then we'll be able to remove <code>#[macro_use]</code> on modules as well.<br>
And <code>#[macro_use] extern crate</code> is already redundant and can be removed, except that would be kind of a hit to ergonomics.</p>



<a name="213886799"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20rid%20of%20%60%23%5Bmacro_export%5D%20macro_rules%60%20on%202021%20edition/near/213886799" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20rid.20of.20.60.23.5Bmacro_export.5D.20macro_rules.60.20on.202021.20edition.html#213886799">(Oct 20 2020 at 08:12)</a>:</h4>
<p>Decl macro 2.0 already has this.</p>



<a name="213888560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20rid%20of%20%60%23%5Bmacro_export%5D%20macro_rules%60%20on%202021%20edition/near/213888560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20rid.20of.20.60.23.5Bmacro_export.5D.20macro_rules.60.20on.202021.20edition.html#213888560">(Oct 20 2020 at 08:31)</a>:</h4>
<p>Yeah, if we do all of the changes mentioned above it will basically mean "upgrade to macros 2.0 in everything that happens "outside" of the macros".</p>



<a name="213984703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20rid%20of%20%60%23%5Bmacro_export%5D%20macro_rules%60%20on%202021%20edition/near/213984703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20rid.20of.20.60.23.5Bmacro_export.5D.20macro_rules.60.20on.202021.20edition.html#213984703">(Oct 20 2020 at 21:57)</a>:</h4>
<p>PR implementing <code>pub macro_rules</code> - <a href="https://github.com/rust-lang/rust/pull/78166">https://github.com/rust-lang/rust/pull/78166</a></p>



<a name="213991253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Getting%20rid%20of%20%60%23%5Bmacro_export%5D%20macro_rules%60%20on%202021%20edition/near/213991253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Getting.20rid.20of.20.60.23.5Bmacro_export.5D.20macro_rules.60.20on.202021.20edition.html#213991253">(Oct 20 2020 at 23:20)</a>:</h4>
<p>Wow, it is indeed quite simple! I guess that's what happens when the logic is already there for macros 2.0 and "all one has to do" is removing artificial safeguards <span aria-label="big smile" class="emoji emoji-1f604" role="img" title="big smile">:big_smile:</span></p>
<p>Given that the change is only adding usability, I like it a lot; but rustdoc would need to catch up (I am currently working on a PR for that: are <code>pub macro{,_rules!}</code> intended to remain in <code>Crate.exported_macros</code> instead of their defining module?)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>